package com.algomypractice.sort.timecomplexityon2;

import com.annotation.service.SortTest;

/**
 * @author: ZhouBert
 * @date: 2019/6/13
 * @description: 选择排序
 */
public class SelectionSort {

	@SortTest
	public static void selectionSort(int[] arr) {
		int len = arr.length;
		for (int j = 0; j < len - 1; j++) {
			int temp = 0;
			int min = arr[j];
			int minIndex = j;
			for (int i = j; i < len; i++) {
				if (arr[i] < min) {
					minIndex = i;
					min = arr[minIndex];
				}
			}
			if (minIndex != j) {
				temp = arr[minIndex];
				arr[minIndex] = arr[j];
				arr[j] = temp;
			}
		}

	}
}
